home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 1.iso / util / thedit20.zip / append.the next >
Text File  |  1995-01-26  |  3KB  |  66 lines

  1. /*
  2. $Id: APPEND.THE 2.0 1995/01/26 16:34:24 MH Release MH $
  3. */
  4. /***********************************************************************/
  5. /* Description: REXX macro to append a string to a line.               */
  6. /* Syntax:      append target string                                   */
  7. /* Notes:       This macro appends the supplied string to the lines    */
  8. /*              specified in the target.                               */
  9. /*              Full XEDIT/KEDIT/THE targets are supported.            */
  10. /*              A single character delimits the beginning of the string*/
  11. /*              to be appended.                                        */
  12. /*              eg. append /fred/ | /bob/ xyz                          */
  13. /*                                       ^ 1 space                     */
  14. /*                  will append 'xyz' to the end of each line          */
  15. /*              eg. append /fred/ | /bob/  xyz                         */
  16. /*                                       ^^ 2 spaces                   */
  17. /*                  will append ' xyz' to the end of each line         */
  18. /*              eg. append /fred/ | /bob/xyz                           */
  19. /*                                      ^ no spaces                    */
  20. /*                  will append 'yz' to the end of each line           */
  21. /***********************************************************************/
  22. Trace o
  23. arg1 = Arg(1)
  24. noargs = Arg()
  25. If noargs = 0 Then arg1 = '1'               /* no args - assume 1 line */
  26. forward = 1                  /* assume direction is forward by default */
  27. 'EXTRACT /LINE/SIZE/STAY/FTYPE/FNAME/'            /* get various stuff */
  28. current_line = line.1                   /* save current line for later */
  29. reply = valid_target(arg1,spare)           /* validate supplied target */
  30. If reply = 'ERROR' Then
  31.    Do
  32.      'EMSG Error: 17 Invalid target' arg1
  33.      Exit
  34.    End
  35. If reply = 'NOTFOUND' Then
  36.    Do
  37.      'EMSG Error: 17 Target not found' arg1
  38.      Exit
  39.    End
  40. start_line = Word(reply,1)                        /* get starting line */
  41. nolines = Word(reply,2)                         /* get number of lines */
  42. start_string = Wordindex(reply,2) + Wordlength(reply,2) + 2
  43. string = Substr(reply,start_string) /* rest of argument is append string */
  44. If nolines < 0 Then Do                /* if target before current line */
  45.    forward = 0                    /* indicate direction to be backward */
  46.    nolines = nolines * -1                     /* make nolines positive */
  47. End
  48. ':'||start_line                                    /* go to first line */
  49. totlines = 0                             /* reset changed line counter */
  50. Do nolines                              /* for each line to target ... */
  51.    'EXTRACT /CURLINE/TOF/EOF/'       /* get current line contents, etc.*/
  52.    If tof.1 = 'ON',                    /* ignore line if on TOF or EOF */
  53.    |  eof.1 = 'ON' Then nop
  54.    Else
  55.      Do
  56.        'REPLACE' curline.3||string
  57.        totlines = totlines + 1
  58.      End
  59.    If forward = 1 Then 'N'          /* if going forward, get next line */
  60.    Else 'U'                   /* if going backwards, get previous line */
  61.    If rc \= 0 Then Leave                         /* shouldn't get here */
  62. End
  63. 'EMSG' "'"||string||"'" 'appended to' totlines 'lines' /* say how many lines changed */
  64. If stay.1 = 'ON' Then ':'||current_line 
  65. Return                                               /* go back to THE */
  66.